#第一周作业3 自动取款机的存取款模拟效果

#自动取款机的存取款模拟效果
users = [
			{'name':'zhangsan', 'pass':'123', 'balance':2000},
			{'name':'lisi', 'pass':'456', 'balance':3000},
			{'name':'wangwu', 'pass':'789', 'balance':4000}
		]

def check(uid):
	'''
	查询当前用户余额,返回列表
	'''
	global users
	print('-'*40)
	print('{0:2}{1:<20}| {2:<11}'.format(' ', '用户名', '账户余额'))
	print('-'*40)
	print('{0:2}{1:<23}| {2:<11}'.format(' ', users[uid]['name'], users[uid]['balance']))
	print('-'*40)

islogin = False
key = 0
while True:
	if key == 1:
		uname = input('请输入用户名:')
		upass = input('请输入密码:')
		for i in range(len(users)):
			if users[i]['name']==uname and users[i]['pass']==upass:
				uid = i
				islogin = True
				print('登录成功!')
				key = 0
				break
			elif users[i]['name']==uname and users[i]['pass']!=upass:
				upass = input('密码错误,请重新输入:')
		else:
			print('无此用户!')
			key == 1
			break
		continue
	elif key == 2:
		if not islogin:
			print('请登录系统后再操作')
		else:
			check(uid)
		key = 0
		continue
	elif key == 3:
		if not islogin:
			print('请登录系统后再操作')
		else:
			money = int(input('请输入金额:'))
			while money:
				if users[uid]['balance'] < money:
					print('余额不足!')
					money = int(input('请重新输入:'))
					continue
				else:
					users[uid]['balance'] -= money
					print('取钱成功,注意查收!')
					check(uid)
					break
		key = 0
		continue
	elif key == 4:
		money = int(input('请输入金额:'))
		while money<0:
			money = int(input('请重新输入大于0的整数:'))
			continue
		users[uid]['balance'] += money
		check(uid)
		key = 0
		continue
	elif key == 5:
		print('谢谢您的使用,再见!')
		break
	else:
		if not islogin:
			key = 1
			continue
		else:
			print('{0:1}{1:<15}{2:15}'.format(' ', '2.查询余额', '3.取款'))
			print('{0:1}{1:<15}{2:15}'.format(' ', '4.存款', '5.退出系统'))
		key = int(input('请输入操作序号:'))